﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using SmartSpace.Core;
using SsTool.Base.Windows;

namespace SsTool.Base
{
    /// <summary>
    /// Interaction logic for ModuleListPage.xaml
    /// </summary>
    public partial class ModuleListPage : Page
    {
        public ModuleListPage()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(ModuleListPage_Loaded);
        }

        void ModuleListPage_Loaded(object sender, RoutedEventArgs e)
        {
            LoadDatas();
        }

        private void LoadDatas()
        {
            ICoreService service = App.Get<ICoreService>();
            List<Module> modules = service.GetModules(0, 999);
            _ctlGridModules.ItemsSource = modules;
        }

        private void _ctlBtnCreate_Click(object sender, RoutedEventArgs e)
        {
            ModuleWindow window = new ModuleWindow();
            if (window.ShowDialog() == true)
            {
                LoadDatas();
            }
        }

        private void _ctlGridModules_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Module selectedModule = _ctlGridModules.SelectedItem as Module;
            if (selectedModule == null)
            {
                _ctlGridViews.ItemsSource = null;
            }
            else
            {
                _ctlGridViews.ItemsSource = selectedModule.Views;
            }
        }
    }
}
